//
//  SYChuangJianView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2019/4/20.
//  Copyright © 2019年 SanYi. All rights reserved.
//

#import "SYChuangJianView.h"
#import "SYBackTopView.h"
#import "SYChuangTableViewCell.h"
#import "SYChuangHeaderView.h"
#import "SYAddMembersView.h"
#import "SYAddMembersTableViewCell.h"


@interface SYChuangJianView () <UITableViewDelegate,UITableViewDataSource>
@property (strong, nonatomic) SYBackTopView *backView;//顶部viwe
@property (nonatomic, strong) UIButton *addBtn;//添加按钮
@property (nonatomic, strong) UITableView *curTableView;

@end


@implementation SYChuangJianView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
        [self initSubView];
    }
    return self;
}
- (void)initSubView {
    [self addSubview:self.backView];
    [self.backView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(50);
    }];
    [self.backView addSubview:self.addBtn];
    [self.addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.backView.mas_right).offset(-20);
        make.centerY.equalTo(self.backView.mas_centerY);
        make.width.height.mas_equalTo(40);
    }];
    
    //表
    [self addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.backView.mas_bottom).offset(0);
        make.left.equalTo(self).offset(14);
        make.right.equalTo(self.mas_right).offset(-14);
        make.bottom.equalTo(self.mas_bottom).offset(-14);
    }];
}
#pragma mark - tab
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 223+38;
    } else {
        return 159;
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        SYChuangTableViewCell *wCell =[tableView dequeueReusableCellWithIdentifier:@"SYChuangTableViewCell" forIndexPath:indexPath];
        wCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [wCell chuangjianTableViewIndexPath:indexPath];
        return wCell;
    } else {
        SYAddMembersTableViewCell *wCell =[tableView dequeueReusableCellWithIdentifier:@"SYAddMembersTableViewCell" forIndexPath:indexPath];
        wCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [wCell chuangjianTableViewIndexPath:indexPath];
        return wCell;
        
    }
    
    
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [UIView new];
    if (section == 0) {
        SYChuangHeaderView *headerView = [[SYChuangHeaderView alloc] initWithType:SYChuangHeaderViewTypeShiXun];
        [view addSubview:headerView];
        [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(view).offset(14);
            make.right.equalTo(view).offset(-14);
            make.bottom.equalTo(view.mas_bottom).offset(0);
        }];
    } else {
        SYAddMembersView *membersView = [[SYAddMembersView alloc] init];
        [view addSubview:membersView];
        [membersView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(view).offset(14);
            make.right.equalTo(view).offset(-14);
            make.bottom.equalTo(view.mas_bottom).offset(0);
        }];
    }
    
    
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
    UIView *topView = [UIView new];
    topView.backgroundColor = [UIColor colorWithHexString:@"F8F8F8"];
    [view addSubview:topView];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view);
        make.left.equalTo(view.mas_left).offset(14);
        make.right.equalTo(view.mas_right).offset(-14);
        make.height.mas_equalTo(1);
    }];
    return view;
}

#pragma mark -保存按钮
- (void)chuangAddBtnClick {
    
}

#pragma mark - set
//头部
- (SYBackTopView *)backView {
    if (!_backView) {
        _backView = [[SYBackTopView alloc] initWithTitleName:@"创建小组" baseView:self];
    }
    return _backView;
}
//添加
- (UIButton *)addBtn {
    if (!_addBtn) {
        _addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addBtn addTarget:self action:@selector(chuangAddBtnClick) forControlEvents:UIControlEventTouchUpInside];
        _addBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [_addBtn setTitleColor:[UIColor colorWithHexString:@"#F8F8F8"] forState:0];
        [_addBtn setTitle:@"保存" forState:UIControlStateNormal];
    }
    return _addBtn;
}
- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
        
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _curTableView.backgroundColor = [UIColor whiteColor];
        [_curTableView registerCellWithClassNames:@[@"SYChuangTableViewCell",@"SYAddMembersTableViewCell"]];
    }
    return _curTableView;
}


@end






























